package com.gxkj.projects.myshopx.dao;

import com.gxkj.common.hibernate.HibernateBaseRepositoryImpl;
import com.gxkj.common.utils.ListPager;
import com.gxkj.projects.myshopx.entitys.Brand;
import com.gxkj.projects.myshopx.entitys.Category;
import com.gxkj.projects.myshopx.enums.CategoryState;
import com.gxkj.projects.myshopx.enums.GoodTypeStates;
import org.springframework.stereotype.Repository;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Repository
public class CategoryDaoImpl  extends HibernateBaseRepositoryImpl {

    public ListPager<Category> doPageHQL(int pagenNo, int pageSize, Category entity){
        ListPager<Category> pager = new ListPager<Category>();
        pager.setPageNo(pagenNo);
        pager.setRowsPerPage(pageSize);
        String hql  = " from Category c   ";
        Map<String,Object> param = new HashMap<String,Object>();
        if(entity == null || entity.getStates() == null){
            hql += " where states != :states";
            param.put("states", CategoryState.DEL);
        }else {
            hql += " where  1 = 1";
        }


        return  this.selectPageByHql(hql,param,pager);
    }

    public List<Category> getByParentIdHQL(int pagenNo, int pageSize, String parentId){
        ListPager<Category> pager = new ListPager<Category>();
        pager.setPageNo(pagenNo);
        pager.setRowsPerPage(pageSize);

        String hql  = " from Category c   where states != :states and parentId = :parentId";
        Map<String,Object> param = new HashMap<String,Object>();
        param.put("states", CategoryState.DEL);
        param.put("parentId", parentId);
        pager =  this.selectPageByHql(hql,param,pager);
        return pager.getPageData();
    }
}
